package cn.crism.blog.repository;

import cn.crism.blog.entity.Comment;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

public interface CommentRepository extends JpaRepository<Comment,String>{
    Page<Comment> findAllByArticleIdAndCommentStatus(Integer articleId,Boolean commentStatus,Pageable pageable);

    void deleteCommentByArticleId(Integer articleId);

    @Modifying
    @Query(value ="delete from article where article_id = ?1",nativeQuery = true)
    int deleteCommentsByArticleId(Integer articleId);
}
